package com.example.blog1.model;

import com.example.blog1.common.Constants;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;
    private String errMsg;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.code = Constants.RESULT_SUCCESS;
        result.errMsg = "";
        result.data = data;
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result result = new Result<>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

    public static <T> Result<T> fail(String errMsg,T data) {
        Result<T> result = new Result<>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }
}
